package com.springboot.vod.controller;

import com.aliyun.vod.upload.impl.BaseServiceImpl;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.DeleteVideoRequest;
import com.springboot.commonutils.R;
import com.springboot.servicebase.exceptionhandler.GuliException;
import com.springboot.vod.Utile.InitVodCilent;
import com.springboot.vod.service.Impl.VodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduvod/upload")
@CrossOrigin
public class VodController {

    @Autowired
    private VodServiceImpl vodService;


    //上传视频到阿里云
    @PostMapping("uploadAlyiVideo")
    public R uploadAlyiVideo(MultipartFile file) {
        //返回上传视频id
        String videoId = vodService.uploadVideoAly(file);
        return R.ok().data("videoId",videoId);
    }
    //根据视频id删除阿里云视频
    @DeleteMapping("removeAlyVideo/{id}")
    public R removeAlyVideo(@PathVariable String id) {
        try {
            //初始化对象
            DefaultAcsClient client = InitVodCilent.initVodClient("LTAI4GFHKf74Y14gAATonWdQ", "ZP2o7qKto6K7gTGjbzIOUk60HocBdi");
            //创建删除视频request对象
            DeleteVideoRequest request = new DeleteVideoRequest();
            System.out.println(id);
            //向request设置视频id
            request.setVideoIds(id);
            //调用初始化对象的方法实现删除
            client.getAcsResponse(request);
            return R.ok();
        }catch(Exception e) {
            e.printStackTrace();
            throw new GuliException(20001,"删除视频失败");
        }
    }
    //删除多个视频
    @DeleteMapping("removeList")
    public R removeList(@RequestParam("id") List id){
        vodService.removelistvoide(id);
        return R.ok();
    }


}
